package com.xci.edu.module.foreground.pc.train.controller;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BoolResult;
import com.xci.edu.core.entity.EduCourseware;
import com.xci.edu.core.entity.EduStudent;
import com.xci.edu.core.entity.EduStudentPeriodDetails;
import com.xci.edu.core.entity.EduStudentPeriodSummary;
import com.xci.edu.core.filter.EduCoursewareFilter;
import com.xci.edu.core.filter.EduStudentPeriodDetailsFilter;
import com.xci.edu.core.filter.EduStudentPeriodSummaryFilter;
import com.xci.edu.core.service.EduCoursewareService;
import com.xci.edu.core.service.EduStudentPeriodDetailsService;
import com.xci.edu.core.service.EduStudentPeriodSummaryService;
import com.xci.edu.core.service.TrainStudentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 学员学时页面控制器
 * @author 焦元义 jiaoyuanyi@xci96716.com
 * @since 2020-12-09 15:14:37
 */
@Controller
@RequestMapping("/train/eduStudentPeriod")
public class EduStudentPeriodController {

    /** 学员培训登录 */
    @Resource
    private TrainStudentService trainStudentService;

    /** 课程信息服务 */
    @Resource private EduCoursewareService eduCoursewareService;

    /** 学员学时汇总服务 */
    @Resource private EduStudentPeriodSummaryService eduStudentPeriodSummaryService;

    /** 在学课程页面 */
    @GetMapping("/student_period_index")
    public String studentPeriod(@ModelAttribute EduStudent entity, ModelMap map) {
//        entity =trainStudentService.getCurrentStudent();
//        entity=eduStudentPeriodDetailsService.selectList(categoryId);
//        entity.setCourseType("0");
//        map.put("entity", entity);
//        return "background/eduStudentPeriodDetails/student_period";
        return "foreground/pc/train/eduStudentPeriodDetails/index";
    }

    /** 取出学员相应的课程 */
    @GetMapping("/student_period_data")
    public String studentPeriodData(EduStudentPeriodSummaryFilter filter, ModelMap map) {
        filter.setEduCategoryId(trainStudentService.getCurrentStudent().getEduCategoryId());
        filter.setStudentId(trainStudentService.getCurrentStudent().getId());
        var entityList =eduStudentPeriodSummaryService.selectPeriodToStudent(filter);
        map.put("entityList", entityList);
        return "foreground/pc/train/eduStudentPeriodDetails/edu_data";
    }

//    /** 表格查询 */
//    @ResponseBody
//    @PostMapping("/grid")
////    @Authorize(code = "background.eduStudentPeriodDetails.select")
//    public BoolResult grid() {
//        EduStudentPeriodSummaryFilter filter = new EduStudentPeriodSummaryFilter();
//        filter.setEduCategoryId(trainStudentService.getCurrentStudent().getEduCategoryId());
//        return BoolResult.success(eduStudentPeriodSummaryService.selectPeriodToStudent(filter));
//    }

    /** 学习页面 */
    @GetMapping("/student_period")
//    @Authorize(code = "background.eduStudentPeriodDetails.validate")
    public String studentPeriod(String courseType, ModelMap map) {
        EduStudentPeriodDetails entity=new EduStudentPeriodDetails();
        entity.setCourseType(courseType);
        map.put("entity", entity);
        return "background/eduStudentPeriodDetails/student_period";
    }

}
